<?php

class Scrollers {
	
	public static $page_cur;
	
	public static function scroller($get_page, $all, $onepage, $page_rng, $id_cat = null) {
		Scrollers::$page_cur = $get_page ? $get_page : 1; // current page index
		$page_cnt = ceil ( $all / $onepage ); // total number of pages
		$page_bgn = Scrollers::$page_cur <= $page_rng ? 1 : Scrollers::$page_cur - $page_rng; // index of the first page in scroller
		$page_end = Scrollers::$page_cur + $page_rng > $page_cnt ? $page_cnt : Scrollers::$page_cur + $page_rng; // index of the last page in scroller
		

		$path = isset ( $id_cat ) ? "category=$id_cat" : null;
		$scroller = '';
		$page = 0;
		// start from "got to first page" if required
		if (Scrollers::$page_cur - $page_rng > 1) {
			$href = $path ? $_SERVER [PHP_SELF] . "?$path&page=1" : $_SERVER [PHP_SELF] . "?page=1";
			$scroller .= '<span><a href="' . $href . '">' . str_repeat ( Messages::$lt, 3 ) . '</a></span>&nbsp;';
		}
		// build scroller     
		for($page = $page_bgn; $page <= $page_end; $page ++) {
			if ($page == Scrollers::$page_cur) {
				$scroller .= Messages::$sqrBracketLft . $page . Messages::$sqrBracketRgt . "\n";
			} else {
				$href = $path ? $_SERVER [PHP_SELF] . "?$path&page=$page" : $_SERVER [PHP_SELF] . "?page=$page";
				$scroller .= Messages::$sqrBracketLft . '<a href="' . $href . '">' . $page . '</a>' . Messages::$sqrBracketRgt . "\n";
			}
		}
		// add "got to last page" if required	
		if (Scrollers::$page_cur + $page_rng < $page_cnt) {
			$href = $path ? $_SERVER [PHP_SELF] . "?$path&page=$page_cnt" : $_SERVER [PHP_SELF] . "?page=$page_cnt";
			$scroller .= '&nbsp;<span><a href="' . $href . '">' . str_repeat ( Messages::$gt, 3 ) . '</a></span>';
		}
		
		return $scroller;
	
	}
}

?>
